# Pilot Festival Data ---------------------------------------------------

# Get names of all counts of visits
attendance_count_vars <-
	names(festival_pilot)[grepl(pattern = "n_",
														x = names(festival_pilot),
														ignore.case = F)]

# Remove variables that include children and teenagers and interruptions
attendance_count_vars <-
	attendance_count_vars[!grepl("children|teenager|interr", attendance_count_vars)]

# Get total vists by men and women at all six films for every cluster
attendance <- festival_pilot[, attendance_count_vars]

attendance <-
	# Fix non-numeric inputs by enumerators
	attendance %>%
	mutate(
		n_men_4 = case_when(
			n_men_4 == "18/16" ~ as.integer(round((18 + 16) / 2)),
			n_men_4 == "35/28" ~ as.integer(round((35 + 28) / 2)),
			n_men_4 == "23-Jun" ~ NA_integer_,
			n_men_4 == "" ~ NA_integer_,
			TRUE ~ as.integer(n_men_4)
		),
		n_women_4 = case_when(
			n_women_4 == "12-Sep" ~ NA_integer_,
			n_women_4 == "16/17" ~ as.integer(round((16 + 17) / 2)),
			n_women_4 == "10-Nov" ~ NA_integer_,
			n_women_4 == "" ~ NA_integer_,
			TRUE ~ as.integer(n_women_4)
		)
	) %>%
	mutate_at(.vars = attendance_count_vars, .funs = as.integer) %>%
	mutate(
		n_end1 = n_men_1 + n_women_1,
		n_end2 = n_men_2 + n_women_2,
		n_end3 = n_men_3 + n_women_3,
		n_end4 = n_men_4 + n_women_4
	)


# Take mean of all festival_pilot, ignoring ones where men or women counts
# were missing
festival_pilot$n_end_mean <- rowMeans(attendance[, c("n_end1",
																									 "n_end2",
																									 "n_end3",
																									 "n_end4")], na.rm = TRUE)